import {MouseEventType} from './EventType.js'
export default class Draw{
    constructor(viewer, eventsManager){
        this._viewer =viewer;
        this._delegate =undefined;
        this._floatingAnchor =undefined;
        this._clampToGround =true;
        this._eventsManager =eventsManager;
        // 绘图事件，用来绑定绘制完成后的回调函数
        this._event =new Cesium.Event();
    }
    bindDrawEvent(callback,context){
        let removeCallback =undefined;
        if(callback){
            removeCallback =this._event.addEventListener(callback,context||this)
        }
        return removeCallback;
    }
    _mountEntity(){}

    _onClick(e){
        console.log(e)
    }

    _onMouseMove(e){
        console.log(e)
    }

    _onRightClick(e){
        // info

    }

    createAnchor(position, isCenter =false){
        return this._viewer.entities.add({
            position:position,
            billboard:{
                image: '/images/circle.png',
                width:30,
                height:30,
                eyeOffset: new Cesium.Cartesian3(0,0,-500),
                heightReference:
                    this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
                    this._clampToGround
                        ? Cesium.HeightReference.CLAMP_TO_GROUND
                        : Cesium.HeightReference.NONE
            }
        })
    }

    removeAnchor(entity){
        this._viewer.entities.remove(entity);
    }

    bindEvent(){
        this._eventsManager.on(MouseEventType.CLICK, this._onClick, this)
        this._eventsManager.on(MouseEventType.MOUSE_MOVE, this._onMouseMove,this)
        this._eventsManager.on(MouseEventType.RIGHT, this._onRightClick, this)
    }

    unbindEvent(){
        this._eventsManager.off(MouseEventType.CLICK,this._onClick,this);
        this._eventsManager.off(MouseEventType.MOUSE_MOVE, this._onMouseMove, this);
        this._eventsManager.off(MouseEventType.RIGHT, this._onRightClick, this);
    }

    start(){
        this._mountEntity();
        this.bindEvent();
    }
}